package com.codelathe.gwt.client;

import com.google.gwt.core.client.JavaScriptObject;

/*
 * Test program for SoundManager
 */
public class Sound {
	private JavaScriptObject m_sobj;
	public  static final int SM_UNINITIALIZED = 0;
	public  static final int SM_LOADING = 1;
	public  static final int SM_LOADERROR = 2;
	public  static final int SM_LOADSUCCESS = 3;
	public  static final int PLAYSTATE_STOPPED = 0;
	public  static final int PLAYSTATE_PLAYING = 1;
	
	public Sound(JavaScriptObject obj)
	{
		m_sobj = obj;
	}
	
	/**
     * Returns the ID of the Sound object.
     * @return ID of Sound.
     */
	public native String getID()/*-{
		return this.@com.codelathe.gwt.client.Sound::m_sobj.sID;
	}-*/;
	
	/**
     * Returns the URL of the Sound object.
     * @return url of Sound.
     */
	public native String getURL()/*-{
		return this.@com.codelathe.gwt.client.Sound::m_sobj.url;
	}-*/;
	
	/**
     * Returns the bytes loaded for the Sound object.
     * @return bytes loaded for the Sound.
     */
	public native int getBytesLoaded()/*-{
		return this.@com.codelathe.gwt.client.Sound::m_sobj.bytesLoaded;
	}-*/;

	/**
     * Returns the bytes loaded for the Sound object.
     * @return bytes loaded for the Sound.
     */
	public native int getTotalBytes()/*-{
		return this.@com.codelathe.gwt.client.Sound::m_sobj.bytesTotal;
	}-*/;

	/**
     * Sets the position of the play in the loaded sound/song
     * Can be used to seek to a certain position in the sound/song  
     * @param msec position in milli-seconds.
     */
	public native void setPosition(int msec)/*-{
		this.@com.codelathe.gwt.client.Sound::m_sobj.setPosition(msec);
	}-*/;
	
	/**
     * Gets the current position of play in the loaded sound/song
     * in seconds
     */
	public native double getPosition()/*-{
		var pos = this.@com.codelathe.gwt.client.Sound::m_sobj.position;
		if(isNaN(pos) || pos == null)
			return 0;
		return pos/1000;
	}-*/;
	
	/**
     * Gets the play duration for the current sound/song 
     * in seconds
     */
	public native double getDuration()/*-{
		var dur = this.@com.codelathe.gwt.client.Sound::m_sobj.duration;
		if(isNaN(dur) || dur == null)
			return 0;
		return dur/1000;
	}-*/;
	
	/**
     * Gets the estimated play duration for the current sound/song 
     * in seconds
     */
	public native double getDurationEstimate()/*-{
		var dur = this.@com.codelathe.gwt.client.Sound::m_sobj.durationEstimate;
		if(isNaN(dur) || dur == null)
			return 0;
		return dur/1000;
	}-*/;

	/**
     * Gets the estimated play duration for the current sound/song 
     * in seconds <br>
     * Valid values are PLAYSTATE_STOPPED, PLAYSTATE_PLAYING
     */
	public native int getPlayState()/*-{
		return this.@com.codelathe.gwt.client.Sound::m_sobj.playState;
	}-*/;
	
	/**
     * Returns the status of the Sound.
     * @return status of Sound Object.
     * Valid values are SM_UNINITIALIZED, SM_LOADING, SM_LOADERROR, SM_LOADSUCCESS
     */
	public native int getReadyState()/*-{
		return this.@com.codelathe.gwt.client.Sound::m_sobj.readyState;
	}-*/;
	
	
	public native void play()/*-{
		this.@com.codelathe.gwt.client.Sound::m_sobj.play();
	}-*/;
	
	public native void stop()/*-{
		this.@com.codelathe.gwt.client.Sound::m_sobj.stop();
	}-*/;

	public native void pause()/*-{
		this.@com.codelathe.gwt.client.Sound::m_sobj.pause();
	}-*/;
	
	public native void resume()/*-{
		this.@com.codelathe.gwt.client.Sound::m_sobj.resume();
	}-*/;

	public native void togglePause()/*-{
		this.@com.codelathe.gwt.client.Sound::m_sobj.togglePause();
	}-*/;
	
	public native void mute()/*-{
		this.@com.codelathe.gwt.client.Sound::m_sobj.mute();
	}-*/;

	public native void unmute()/*-{
		this.@com.codelathe.gwt.client.Sound::m_sobj.unmute();
	}-*/;

	public native void destruct()/*-{
	this.@com.codelathe.gwt.client.Sound::m_sobj.destruct();
	}-*/;
	
	private static Sound instance(JavaScriptObject jsObj) {
        return new Sound(jsObj);
    }
}